package com.etc.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.City;
import com.etc.entity.HotelMessage;
import com.etc.po.HoteliDataApi;
import com.etc.service.CityService;

@Controller
@RequestMapping(value="hotel")
public class HotelController {
	
	@Resource
	HoteliDataApi hdapi;
	
	@Resource
	CityService cservice;
	
	@RequestMapping(value="hot")
	@ResponseBody
	public List<HotelMessage> findHotHotel(@RequestParam(value = "cname", defaultValue = "厦门市")String cname) throws IOException, JSONException{
		
		String reg = "^-?[1-9]\\d*$";
		boolean flag =cname.matches(reg);
		if(flag&&!cname.equals("0")) {
			int cid = Integer.parseInt(cname);
			City c =  cservice.findcityByCid(cid);
			cname = c.getCityname();
		}else if(cname.equals("0")){
			cname = "北京市";
		}
			cname = cname.substring(0, 2);
			//System.out.println("pname:"+cname);
			List<HotelMessage> list=hdapi.findHotel(cname,"五星级/豪华");
			/*if(list==null||list.size()<4) {
				List<HotelMessage> list2=hdapi.findHotel(cname,"豪华");
				if(list2!=null) {
					for(int i = 0 ; i <list2.size();i++) {
						list.add(list2.get(i));
					}
				}
			}*/
		return list;
		
	}

}
